
using UnityEngine;

namespace Unity.Game.ElisAdvance.MonsterScript
{
    public class VoidWalkerScript
    {

        private EnemyActiveObject obj;

        public VoidWalkerScript(EnemyActiveObject active)
        {
            obj = active;
        }

        public void onInit()
        {
            obj.initActiveObjectAttackEvent();
            obj.setState(State.STATE_STAND);
            obj.getAttackInfo().setEnable(true, "PLAYER");
            obj.setTeam(Team.MONSTER);
            obj.setCateory(ActiveObjectCateory.FIXTURE);

        }

        public void onSetState(State state)
        {
            if (state == State.STATE_ATTACK)
            {
                if (obj.getAttackIndex() == 0)
                {
                    ActiveObject target = obj.getTarget();
                    EnemyAction.setDirectionToTarget(obj, target);
                }
            }

        }

        public void onDestroy()
        {

            GameObject explosion = obj.getPool().get(0);
            //VoidWalkerDieExplosionEvent

            if (explosion)
            {
                SendActiveObjectCreatePacket sp = new SendActiveObjectCreatePacket();
                sp.startWriteFloat();
                sp.writeFloat(10);
                sp.writeFloat(10);
                sp.writeFloat(0);
                sp.writeFloat(0);
                sp.writeFloat(obj.getXPos());
                sp.writeFloat(obj.getYPos());
                sp.writeFloat(Dir.directionToNum(obj.getDirection()) );
                ActiveObject exp = sp.createActiveObject(explosion,obj);
                exp.getVar("explosionRate").clear_vector();
                exp.getVar("explosionRate").push_vector(1);
            }

        }


        public void onDamage(ActiveObject attacker, float damage, DamageBounsType type, params float[] vector)
        {
            //Debug.Log("hitCount");
            //obj.setShake(CameraShakeType.HORIZONTAL, 1.0f, 0.2f);
        }

        // Update is called once per frame
        public void onProc()
        {

            if (Com.checkObjectTime(obj, "ResetHitTime", 0.5f))
            {
                obj.getAttackInfo().resetHitObjectList();
            }

            AttackObjectTempVector hit = obj.getAttackInfo().onInAreaAttack(-0.25f, 0.0f, 0.5f, 0.5f);  
            hit.sendHit(obj, 1.0f, DamageBounsType.PUSH, 3.0f, 2.0f,0.5f);

        }

    }

}
